/* =============================================================
* VARIABLES
* ============================================================*/
$prefix: 'vhd__datepicker';
$white: #fff;
$black: #000;
$gray: #424b53;
$primary-text-color: #35343d;
$primary-text-inverse-color: #fff;
$lightest-gray: #f3f5f8;
$primary-color: #0fb8ad;
$medium-gray: #424b53;
$light-gray: #eaeaea;
$disabledBg: #f5f7f8;
$disabled-color: #d8d8d8;
$dark-gray: #2d3047;
$box-shadow: 0 0 10px 3px rgba(red, 0.4);
$background-color: #fff;

// Bg Date when hover it
$bgValidHoverDate: $primary-color;
$colorValidHoverDate: $white;

// Bg Date when range or valid it
$bgRollActiveDage: $primary-color;
$colorRollActiveDage: $white;

$font-size: 16px;
$font-small: #{$font-size * 0.875};
$font-family: 'Source Sans Pro', sans-serif, verdana, arial;
$font-regular: 400;
$font-bold: 700;
$tooltip-font-size: 11px;

$width-half-day: 120px;
$bullet-size: 4px;

$tooltip-border-width: 4px;
$tooltip-border-radius: 2px;
$border-generic-width: 1px;

/* =============================================================
* RESPONSIVE LAYOUT HELPERS
* ============================================================*/
$tablet: '(min-width: 480px) and (max-width: 767px)';
$phone: '(max-width: 479px)';
$desktop: '(min-width: 768px)';
$up-to-tablet: '(max-width: 767px)';
$extra-small-screen: '(max-width: 23em)';

@mixin focusStyle() {
  &:focus {
    outline: none;
  }
}

@mixin device($device-widths) {
  @media screen and #{$device-widths} {
    @content;
  }
}

/* =============================================================
* BASE STYLES
* ============================================================*/

.#{$prefix} {
  position: absolute;
  top: 3em;
  z-index: 999;
  transition: all 0.2s ease-in-out;
  background-color: $background-color;
  font-size: $font-size;
  font-family: $font-family;
  line-height: 0.875em;
  overflow: hidden;

  &--right {
    right: 0;
  }

  & .vhd__square {
    position: relative;
    width: calc(100% / 7);
    float: left;
    &:last-child {
      margin-bottom: 1.5em;
    }
  }

  button.next--mobile {
    border: $border-generic-width solid $light-gray;
    float: none;
    height: 3.125em;
    width: 100%;
    position: relative;
    appearance: none;
    overflow: hidden;
    position: fixed;
    bottom: 0;
    left: 0;
    outline: none;
    box-shadow: 0 5px 30px 10px rgba($black, 0.08);
    background: white;

    &:after {
      background: transparent url('../images/ic-arrow-right-green.regular.svg') no-repeat center / 8px;
      transform: rotate(90deg);
      content: '';
      position: absolute;
      width: 200%;
      height: 200%;
      top: -50%;
      left: -50%;
    }
  }

  &--closed {
    box-shadow: none;
    max-height: 0;
  }

  &--open {
    box-shadow: 0 15px 30px 10px rgba($black, 0.08);
    max-height: 56.25em;

    @include device($up-to-tablet) {
      box-shadow: none;
      height: 100%;
      left: 0;
      right: 0;
      bottom: 0;
      -webkit-overflow-scrolling: touch !important;
      position: fixed;
      top: 0;
      width: 100%;
    }
  }

  &__header {
    text-align: left;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 0.5em;
  }

  &__header-mobile {
    text-align: left;
    position: absolute;
    width: 100%;
    z-index: 1;
  }

  &__wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
    height: 3em;
    background: $white url('../images/calendar_icon.regular.svg') no-repeat 1em center / 1em;

    & *,
    & *::before,
    & *::after {
      box-sizing: border-box;
    }

    &--grid .vhd__square .#{$prefix}__month-day {
      border: $border-generic-width solid $light-gray;
      margin: -1px 0 0 -1px;
    }

    &--booking {
      .#{$prefix}__month-day-wrapper {
        & .day {
          display: inline;
          text-align: right;
          padding-top: 0.75em;
          padding-right: 0.75em;
          right: 0;
          top: 0;
          transform: none;
        }
      }
      .#{$prefix}__month-day:before {
        display: none;
      }
    }
  }

  &__fullview {
    background: none;
    height: auto;

    .#{$prefix}__close-button,
    .#{$prefix}__dummy-wrapper,
    .#{$prefix}__clear-button,
    .vhd__hide-on-desktop {
      display: none;
    }
    .#{$prefix} {
      position: relative;
      top: 0;
    }

    .vhd__hide-up-to-tablet {
      display: block;
    }

    .#{$prefix}__month-button {
      display: inline-block;
    }

    .#{$prefix}__months {
      position: static;
      margin: 0;
      width: auto;

      &::before {
        display: none;
      }

      &.#{$prefix}__months--full {
        width: 100% !important;
      }
    }
  }

  &__dummy-wrapper {
    border: $border-generic-width solid $light-gray;
    cursor: pointer;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    width: 100%;
    height: 100%;

    &--no-border.#{$prefix}__dummy-wrapper {
      border: 0;
    }

    &--is-active {
      border: $border-generic-width solid $primary-color;
    }
  }

  &__input {
    background: transparent;
    border: 0;
    color: $primary-text-color;
    font-size: $font-small;
    height: 3.43em;
    line-height: 3.43em;
    outline: none;
    padding: 0 1.875em 0.125em;
    text-align: center;
    width: 50%;
    word-spacing: 0.3125em;

    @include focusStyle();

    &::-webkit-input-placeholder,
    &::-moz-placeholder,
    &:-ms-input-placeholder,
    &:-moz-placeholder {
      color: $primary-text-color;
    }

    @include device($phone) {
      text-indent: 0;
      text-align: center;
    }

    &:first-child {
      background: transparent url('../images/ic-arrow-right-datepicker.regular.svg') no-repeat right center / 8px;
      width: 50%;
    }

    &--is-active {
      color: $primary-text-color;
    }

    &--is-active::placeholder {
      color: $primary-text-color;
    }

    &--is-active::-moz-placeholder {
      color: $primary-text-color;
    }

    &--is-active:-ms-input-placeholder {
      color: $primary-text-color;
    }

    &--is-active:-moz-placeholder {
      color: $primary-text-color;
    }

    &--single-date:first-child {
      width: 100%;
      background: none;
      text-align: center;
    }
  }

  &__month-day-wrapper {
    height: 0;
    padding-top: calc(100% - 1px); //fix for safari
    span.day {
      z-index: 1;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }

    .price {
      position: absolute;
      top: 0;
      width: 100%;
      text-align: center;
      font-weight: bold;
      font-size: 0.75em;
    }
  }

  &__month-day {
    visibility: visible;
    text-align: center;
    color: $primary-text-color;
    cursor: pointer;

    @include focusStyle();

    &--today {
      border: 0;

      .#{$prefix}__month-day-wrapper {
        border: 2px solid $primary-color;
        padding-top: calc(100% - 5px);
      }
    }

    &--invalid-range {
      background-color: rgba($primary-color, 0.3);
      color: $lightest-gray;
      cursor: not-allowed;
      position: relative;
    }

    &--invalid {
      cursor: not-allowed;
      pointer-events: none;
    }

    &--valid:hover,
    &--allowed-checkout:hover {
      background-color: $primary-color;
      color: $colorValidHoverDate;
    }

    &--disabled {
      opacity: 1;
      background: $disabledBg;
      color: $disabled-color;
      cursor: not-allowed;
      pointer-events: none;
      font-weight: $font-regular;
      span {
        text-decoration: line-through;
      }
    }

    &--valid#{&}--not-allowed,
    &--not-allowed.vhd__currentDay,
    &--valid#{&}--not-allowed:hover {
      color: $primary-text-color;
      font-weight: $font-regular;
      cursor: default;
      background: transparent;
      span {
        text-decoration: none;
      }
    }

    &--hovering#{&}--not-allowed:hover {
      cursor: pointer;
    }

    &--halfCheckIn,
    &--halfCheckOut {
      position: relative;
      overflow: hidden;
      &:before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        -webkit-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
        content: '';
        z-index: -1;
        height: 0;
        width: 0;
        border-bottom: $width-half-day solid $disabledBg;
        border-left: $width-half-day solid transparent;
      }
    }

    &--halfCheckOut {
      &:before {
        border-top: $width-half-day solid $disabledBg;
        border-bottom: 0;
        border-left: 0;
        border-right: $width-half-day solid transparent;
      }
    }

    &--selected {
      background-color: rgba($primary-color, 0.7);
      color: $primary-text-inverse-color;
      span {
        text-decoration: none;
      }
      &:hover {
        font-weight: $font-bold;
        background-color: $bgRollActiveDage;
        color: $colorRollActiveDage;
        z-index: 1;
      }
    }

    &--hovering {
      background-color: rgba($primary-color, 0.7);
      color: $primary-text-inverse-color;
      font-weight: $font-bold;
      cursor: pointer;
      span {
        text-decoration: none;
      }
    }

    &--first-day-selected,
    &--last-day-selected {
      background: $primary-color;
      color: $primary-text-inverse-color;
      cursor: pointer;
      font-weight: $font-bold;
      pointer-events: auto;
      span {
        text-decoration: none;
      }
    }

    &--allowed-checkout {
      color: $medium-gray;
    }

    &--out-of-range {
      color: $lightest-gray;
      cursor: not-allowed;
      font-weight: $font-regular;
      position: relative;
      pointer-events: none;
      span {
        text-decoration: none;
      }
    }

    &--valid {
      cursor: pointer;
      font-weight: $font-bold;
    }

    &--valid#{&}--halfCheckIn#{&}--last-day-selected {
      color: white;
    }

    &--hidden {
      opacity: 0;
      pointer-events: none;
    }
  }

  &__month-button {
    background: transparent url('../images/ic-arrow-right-green.regular.svg') no-repeat center center / 8px;
    width: 2.5em;
    height: 2.5em;
    border: $border-generic-width solid #00ca9d;
    outline: none;
    text-align: center;
    cursor: pointer;
    opacity: 1;
    transition: opacity ease 0.5s;

    &:hover {
      opacity: 0.65;
    }

    @include focusStyle();

    &--prev {
      transform: rotateY(180deg);
    }

    &--next {
      float: right;
    }

    &[disabled] {
      opacity: 0.2;
      cursor: not-allowed;
      pointer-events: none;
    }
  }
  &__inner {
    padding: 0 2.5rem;
    position: relative;
    height: calc(100% - 3em);

    @include device($up-to-tablet) {
      padding: 0;
    }
  }

  &__months-wrapper {
    height: 100%;
    .#{$prefix}__months {
      margin-top: 0;
      height: 100%;
      .#{$prefix}__month .#{$prefix}week-name {
        font-size: 1.25em;
      }
    }
  }

  .vhd__show-tooltip {
    .#{$prefix}__months {
      margin-top: 10em;
      height: calc(100% - 10em);
    }
    .#{$prefix}__tooltip--mobile {
      height: auto;
      opacity: 1;
      padding: 1em;
      visibility: visible;
    }
  }

  &__months {
    @include device($desktop) {
      display: flex;
      flex-wrap: wrap;
      width: 40.625em;
      justify-content: space-between;

      &.#{$prefix}__months--full {
        width: 20.3125em !important;
      }
    }

    @include device($up-to-tablet) {
      margin-top: 5.625em;
      height: calc(100% - 5.625em);
      position: absolute;
      left: 0;
      top: 0;
      overflow-y: scroll;
      right: 0;
      bottom: 0;
      transition: all ease 0.2s;
    }

    &::before {
      content: '';
      background: $light-gray;
      bottom: 0;
      display: block;
      left: 50%;
      position: absolute;
      top: 0;
      width: 1px;

      @include device($up-to-tablet) {
        display: none;
      }
    }

    &--full {
      .#{$prefix}__month {
        width: 100% !important;
        padding: 0;
      }

      &::before {
        display: none;
      }
    }
  }

  &__month {
    font-size: 0.75em;
    width: 50%;
    padding-right: 0.83334em;

    @include device($up-to-tablet) {
      width: 100%;
      padding-right: 0;
      padding-top: 5em;
      height: 30em;

      &:last-of-type {
        margin-bottom: 5.416667em;
      }
    }

    @include device($desktop) {
      &:last-of-type {
        padding-right: 0;
        padding-left: 0.83334em;
      }
    }

    &--with-week-numbers {
      position: relative;

      .#{$prefix}__weeknumbers {
        position: absolute;
        top: 4.5rem;
        bottom: 0.875rem;
        display: flex;
        flex-direction: column;

        &__number {
          display: flex;
          align-items: center;
          width: 2rem;
          height: calc(100% / 6);
          margin: -0.5px 0 0;
        }
      }

      &:first-child {
        padding-left: 2rem;

        .#{$prefix}__weeknumbers {
          left: 0;
        }
      }

      &:last-child {
        padding-right: 2rem;

        .#{$prefix}__weeknumbers {
          right: 0;

          &__number {
            justify-content: flex-end;
          }
        }
      }
    }
  }

  &__month-caption {
    height: 2.5em;
    vertical-align: middle;
  }

  &__month-name {
    font-size: $font-size;
    font-weight: $font-bold;
    margin: 0;
    padding: 0 0 1.625em;
    pointer-events: none;
    text-align: center;
    line-height: 2em;
    height: 2.5em;
    padding-top: 0.5em;

    @include device($up-to-tablet) {
      margin-top: -3.125em;
      margin-bottom: 0;
      position: absolute;
      width: 100%;
    }
  }

  &__week-days {
    height: 2em;
    vertical-align: middle;
  }

  &__week-row {
    height: 2.5em;
    line-height: 2.5em;

    @include device($up-to-tablet) {
      box-shadow: 0px 8px 12px 0px rgba($black, 0.1);
    }
  }

  &__week-name {
    width: calc(100% / 7);
    float: left;
    font-size: 1em;
    font-weight: $font-regular;
    color: $medium-gray;
    text-align: center;
  }

  &__close-button {
    appearance: none;
    background: transparent;
    border: 0;
    color: $primary-text-color;
    cursor: pointer;
    font-size: 1.3125em;
    font-weight: $font-bold;
    margin-top: 0;
    outline: 0;
    z-index: 10000;
    position: fixed;
    right: 0.7143em;
    top: 0;
    height: 2.286em;
    line-height: 2.286em;

    i {
      display: block;
      font-style: inherit;
      transform: rotate(45deg);
    }
  }

  &__clear-button {
    appearance: none;
    background: transparent;
    border: 0;
    cursor: pointer;
    font-size: 1.5625em;
    font-weight: $font-bold;
    height: 100%;
    margin: 0;
    padding: 0;
    position: absolute;
    right: 0;
    top: 0;
    width: 1.6em;

    svg {
      fill: none;
      stroke-linecap: round;
      stroke-width: 0.32em;
      stroke: $medium-gray;
      width: 0.56em;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }

    @include focusStyle();
  }

  &__tooltip {
    background-color: $dark-gray;
    border-radius: $tooltip-border-radius;
    color: $primary-text-inverse-color;
    font-size: $tooltip-font-size;
    padding: 0, 45em 0, 91em;
    position: absolute;
    z-index: 50;
    left: 50%;
    bottom: 100%;
    white-space: nowrap;
    transform: translateX(-50%);
    text-align: center;

    &--mobile {
      height: 0;
      opacity: 0;
      visibility: hidden;
      padding: 0 1.1em;
      border: $border-generic-width solid #d7d9e2;
      font-size: $font-small;
      line-height: 1.4;
      transition: all ease 0.2s;
    }

    &:after {
      border-left: $tooltip-border-width solid transparent;
      border-right: $tooltip-border-width solid transparent;
      border-top: $tooltip-border-width solid $dark-gray;
      bottom: -0.364em;
      content: '';
      left: 50%;
      margin-left: -0.364em;
      position: absolute;
    }
  }
}

.-vhd__is-hidden {
  display: none;
}

.vhd__hide-up-to-tablet {
  @include device($up-to-tablet) {
    display: none;
  }
}

.vhd__hide-on-desktop {
  @include device($desktop) {
    display: none;
  }
}

.vhd__parent-bullet {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  display: block;
  z-index: -1;

  .vhd__bullet {
    position: absolute;
    top: 60%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: $bullet-size;
    transition: opacity ease 0.3s;
    @include device($desktop) {
      top: 50%;
    }

    &.vhd__checkInCheckOut,
    &.vhd__checkIn,
    &.vhd__checkOut {
      width: 0.5em;
      height: 1.125em;
      border-radius: 0.625em;

      &.vhd__bullet--small {
        height: 0.375em;
        width: 0.875em;
      }
    }

    &.vhd__checkInCheckOut {
      left: calc(50% - 1em);
    }
  }

  .vhd__pipe {
    display: block;
    width: 100%;
    height: $bullet-size;
    position: absolute;
    top: 60%;
    transform: translateY(-50%);
    transition: opacity ease 0.3s;
    @include device($desktop) {
      top: 50%;
    }

    &.pipe--small {
      height: calc(#{$bullet-size} * 0.75);
    }

    &.vhd__checkIn {
      left: calc(50% + #{$bullet-size});
      width: calc(50% - #{$bullet-size});
    }

    &.vhd__checkOut {
      left: 0px;
      width: calc(50% - #{$bullet-size});
    }

    &.vhd__checkInCheckOut {
      width: calc(50% - 1.1875em);
    }
  }
}
